// pages/column/index.js
Page({
  /**
   * 页面的初始数据
   */
  onShareAppMessage() {
    return {
      title: "scroll-view",
      path: "page/component/pages/scroll-view/scroll-view",
    };
  },

  data: {
    toView: "green",
    list: [
      {
        img: "/img/column/column1.jpg",
        title: "专栏一",
        text1: "做饭技巧",
        text2: "厨房小白必看",
        likes: "222",
        check: "123",
        liked: true,
        postion: "left",
        content: [
          "/img/column/column1.1.png",
          "/img/column/column1.2.png",
          "/img/column/column1.3.png",
          "/img/column/column1.4.png",
          "/img/column/column1.5.png",
          "/img/column/column1.6.jpg",
        ],
      },
      {
        img: "/img/column/column2.jpg",
        title: "专栏二",
        text1: "厨房用具",
        text2: "厨房好物 推荐",
        likes: "222",
        check: "123",
        postion: "right",
        liked: true,
        content: [
          "/img/column/column2.1.png",
          "/img/column/column2.2.png",
          "/img/column/column2.3.png",
          "/img/column/column2.4.png",
          "/img/column/column2.5.png",
          "/img/column/column2.6.png",
        ],
      },
      {
        img: "/img/column/column3.png",
        title: "专栏三",
        text1: "专属小锅",
        text2: "教你如何烹饪",
        likes: "666",
        check: "666",
        postion: "left",
        color: "white",
        liked: true,
        content: [
          "/img/column/column3.1.png",
          "/img/column/column3.2.png",
          "/img/column/column3.3.png",
          "/img/column/column3.4.png",
          "/img/column/column3.6.png",
          "/img/column/column3.7.png",
        ],
      },
    ],
    isTrigger: false,
  },

  todetail(e) {
    console.log(e.currentTarget.dataset.index);
    let { list } = this.data;
    let index = e.currentTarget.dataset.index;

    let a = JSON.stringify(e.currentTarget.dataset.i);
    let add = list[index].check * 1 + 1;
    console.log(add);
    let checked = "list[" + index + "].check";

    this.setData({
      [checked]: add,
    });
    wx.navigateTo({
      url: `/pages/columndetail/index?item=${a}`,
    });
  },
  like(e) {
    let { list } = this.data;
    let index = e.currentTarget.dataset.index;
    let a = JSON.stringify(e.currentTarget.dataset.i);
    let liked = "list[" + index + "].likes";
    let likedimg = "list[" + index + "].liked";
    if (this.data.list[index].liked) {
      let add = list[index].likes * 1 + 1;
      console.log(add);
      this.setData({
        [liked]: add,
        [likedimg]: false,
      });
    } else {
      let add = list[index].likes * 1 - 1;
      this.setData({
        [liked]: add,
        [likedimg]: true,
      });
    }
  },
  upper(e) {
    // console.log(e);
  },

  lower(e) {
    // console.log(e, 555);

    let newlist = [
      {
        img: "/img/column/column1.jpg",
        title: "专栏一",
        text1: "做饭技巧",
        text2: "厨房小白必看",
        likes: "222",
        check: "123",
        liked: true,
        postion: "left",
        content: [
          "/img/column/column1.1.png",
          "/img/column/column1.2.png",
          "/img/column/column1.3.png",
          "/img/column/column1.4.png",
          "/img/column/column1.5.png",
          "/img/column/column1.6.jpg",
        ],
      },
      {
        img: "/img/column/column2.jpg",
        title: "专栏二",
        text1: "厨房用具",
        text2: "厨房好物 推荐",
        likes: "222",
        check: "123",
        postion: "right",
        liked: true,
        content: [
          "/img/column/column2.1.png",
          "/img/column/column2.2.png",
          "/img/column/column2.3.png",
          "/img/column/column2.4.png",
          "/img/column/column2.5.png",
          "/img/column/column2.6.png",
        ],
      },
      {
        img: "/img/column/column3.png",
        title: "专栏三",
        text1: "专属小锅",
        text2: "教你如何烹饪",
        likes: "666",
        check: "666",
        postion: "left",
        color: "white",
        liked: true,
        content: [
          "/img/column/column3.1.png",
          "/img/column/column3.2.png",
          "/img/column/column3.3.png",
          "/img/column/column3.4.png",
          "/img/column/column3.5.png",
          "/img/column/column3.6.png",
        ],
      },
    ];
    let { list } = this.data;
    for (var i = 0; i < newlist.length; i++) {
      list.push(newlist[i]);
    }
    this.setData({
      list,
    });
  },

  scroll(e) {
    // console.log(e);
  },
  updatelist(e) {
    // console.log(e, 6666666666);
    let list = [
      {
        img: "/img/column/column1.jpg",
        title: "专栏一",
        text1: "做饭技巧",
        text2: "厨房小白必看",
        likes: "222",
        check: "123",
        liked: true,
        postion: "left",
        content: [
          "/img/column/column1.1.png",
          "/img/column/column1.2.png",
          "/img/column/column1.3.png",
          "/img/column/column1.4.png",
          "/img/column/column1.5.png",
          "/img/column/column1.6.jpg",
        ],
      },
      {
        img: "/img/column/column2.jpg",
        title: "专栏二",
        text1: "厨房用具",
        text2: "厨房好物 推荐",
        likes: "222",
        check: "123",
        postion: "right",
        liked: true,
        content: [
          "/img/column/column2.1.png",
          "/img/column/column2.2.png",
          "/img/column/column2.3.png",
          "/img/column/column2.4.png",
          "/img/column/column2.5.png",
          "/img/column/column2.6.jpg",
        ],
      },
      {
        img: "/img/column/column3.png",
        title: "专栏三",
        text1: "专属小锅",
        text2: "教你如何烹饪",
        likes: "666",
        check: "666",
        postion: "left",
        color: "white",
        liked: true,
        content: [
          "/img/column/column3.1.png",
          "/img/column/column3.2.png",
          "/img/column/column3.3.png",
          "/img/column/column3.4.png",
          "/img/column/column3.5.png",
          "/img/column/column3.6.jpg",
        ],
      },
    ];

    this.setData({
      isTrigger: false,
      list : list
    });
    wx.hideLoading();
  },
  scrollToTop() {
    this.setAction({
      scrollTop: 0,
    });
  },

  tap() {
    for (let i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1],
          scrollTop: (i + 1) * 200,
        });
        break;
      }
    }
  },

  tapMove() {
    this.setData({
      scrollTop: this.data.scrollTop + 10,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
